<?php

class Pldkp_View_Helper_Link extends Pldkp_View_Helper_IsUserAllowed
{   
    protected static $_router = null;
    
    public function __construct()
    {
        parent::__construct();
        self::$_router = Zend_Controller_Front::getInstance()->getRouter();
    }
    
    
    function link($title, array $url = array(), array $options = array())
    {
        $url = $this->prepareUrl($url);
        
        if (!$this->isUserAllowed($url)) {
            return '';
        }
        
        $style = '';
        if (isset($options['style'])) {
            $style = ' style=\"' . $options['style'] . '\"';
            unset($options['style']);
        }
        
        $target = '';
        if (isset($options['target'])) {
            $target = ' target="' . $options['target'] . '"';
        }
        
        $class = '';
        if (isset($options['class'])) {
            $target = ' class="' . $options['class'] . '"';
        }
        
        $url = self::$_router->assemble($url, null, true, true);
        $html = '<a href="' . $url . '"' . $style. $target . $class . '>' . $this->view->escape($title) . '</a>';
        
        return $html;
    }
}
